// This file is part of OpenMeca, an easy software to do mechanical simulation.
//
// Author(s)    :  - Damien ANDRE  <openmeca@gmail.com>
//
// Copyright (C) 2012 Damien ANDRE
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.


#ifndef OpenMeca_Item_Drawable_hpp
#define OpenMeca_Item_Drawable_hpp


#include <string>
#include <map>

#include "OpenMeca/Core/AutoRegister.hpp"
#include "OpenMeca/Core/UserItem.hpp"

#include "OpenMeca/Geom/Point.hpp"
#include "OpenMeca/Geom/Quaternion.hpp"
#include "OpenMeca/Geom/Frame.hpp"

#include "OpenMeca/Util/Color.hpp"

namespace OpenMeca
{  
  namespace Item
  {  
    class Body;
  }
  
  namespace Core
  {

    class Drawable : public Core::UserItem, public AutoRegister<Drawable>
    {
    
    public:
      static const std::string GetStrType(); 
      static Drawable& GetDrawableItemByGLKey(int);

      //Static methods that draw misceallous shape
      static void DrawCylinder(float radius, float length, bool middlePositinning=true);
      static void DrawSphere(float radius);

    public:
      Drawable(const std::string strType, QTreeWidgetItem& parent, bool isSelectable);
      virtual ~Drawable();
            
      virtual void DrawShape()  = 0;
      virtual void BeginDraw(){};
      virtual void EndDraw(){};
      
      void Draw(bool withName = false);
      unsigned int GetItemGLKey() const;
      bool IsSelectable() const;

    private:
      Drawable(const Drawable&);             //Not Allowed
      Drawable& operator=(const Drawable&);  //Not Allowed

      friend class boost::serialization::access;
      template<class Archive>
      void serialize(Archive& ar, const unsigned int);
      

    private:
      static int drawableItemCounter_;
      static std::map<int, Drawable*> map_;

    private:
      const unsigned int itemGLKey_;
      bool isSelectable_;

    };

    template<class Archive>
    void Drawable::serialize(Archive& ar, const unsigned int)
    {
      ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(UserItem);
    }



  }

}




#endif
